//package com.tsinghuabigdata.edu.ddmath.MVPPresent;
//
//import android.os.Handler;
//import android.os.Message;
//
//import com.tsinghuabigdata.edu.zxapp.teacher.MVPModel.MessageModel;
//import com.tsinghuabigdata.edu.zxapp.teacher.MVPModel.RequestListener;
//import com.tsinghuabigdata.edu.zxapp.teacher.MVPView.IMessageCenterView;
//import com.tsinghuabigdata.edu.zxapp.teacher.VolleryRequest.HttpResponse;
//import com.tsinghuabigdata.edu.zxapp.teacher.bean.MessageInfo;
//import com.tsinghuabigdata.edu.zxapp.teacher.bean.MessageRet;
//import com.tsinghuabigdata.edu.zxapp.teacher.bean.ResultInfo;
//import com.tsinghuabigdata.edu.zxapp.teacher.constant.AppConst;
//import com.tsinghuabigdata.edu.zxapp.teacher.fragment.MessageFragment;
//import com.tsinghuabigdata.edu.zxapp.teacher.utils.AccountUtils;
//
//import java.util.ArrayList;
//
///**
// * Created by 28205 on 2016/9/2.
// */
//public class MessagePresenter {
//    private static final String TAG = "MessageCenterPresenter";
//
//    private IMessageCenterView msgCenterView;
//    private MessageModel msgModel;
//
//    ArrayList<MessageInfo> messageList = new ArrayList<MessageInfo>();
//
//    String teacherId;
//    String accessToken;
//    String accountId;
//
//    private Handler mHandler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//            switch (msg.what) {
//                case AppConst.PG_STATE_LOAD_FINISH:
////                    msgCenterView.toast("刷新消息成功");
//                    messageList.clear();
//                    messageList.addAll(((MessageRet) msg.obj).getItems());
//
//                    msgCenterView.setMessageData(messageList, msg.arg1);
//                    break;
//                case AppConst.PG_STATE_LOAD_MORE_FINISH:
////                    msgCenterView.toast("加载消息成功");
//                    messageList.clear();
//                    messageList.addAll(((MessageRet) msg.obj).getItems());
//
//                    msgCenterView.addMessageData(messageList, msg.arg1);
//                    break;
//                case AppConst.PG_STATE_LOAD_FINISH_NO_DATA:
//                    break;
//                case AppConst.PG_STATE_LOAD_MORE_FINISH_NO_DATA:
//                    break;
//                case AppConst.PG_STATE_LOAD_FINISH_FAIL:
//                case AppConst.PG_STATE_LOAD_MORE_FINISH_FAIL:
//                    String reason = (String) msg.obj;
//                    msgCenterView.toast(reason);
//                    break;
//                case AppConst.MSG_CLEAN_SUCCESS:
//                    //重新加载消息
//                    msgCenterView.setRefreshState(msg.what, msg.arg1, null);
//                    break;
//                case AppConst.MSG_CLEAN_FAIL:
//                    msgCenterView.toast("消息清除失败");
//                    break;
//            }
//            if (msg.what == AppConst.PG_STATE_LOAD_FINISH_FAIL || msg.what == AppConst.PG_STATE_LOAD_MORE_FINISH_FAIL) {
//                msgCenterView.setRefreshState(msg.what, msg.arg1, null);
//            } else if (msg.what >= AppConst.PG_STATE_LOAD_FINISH) {
//                msgCenterView.setRefreshState(msg.what, msg.arg1, (MessageRet) msg.obj);
//            }
//        }
//    };
//
//    public MessagePresenter(IMessageCenterView msgCenterView) {
//        this.msgCenterView = msgCenterView;
//        msgModel = new MessageModel();
//
//        accessToken = AccountUtils.getLoginUser().getAccess_token();
//        teacherId = AccountUtils.getTeacherDetailInfo().getTeacherId();
//        accountId = AccountUtils.getLoginUser().getAccountId();
//    }
//
//    public int getRetState(int pageNum, MessageRet res) {
//        int state = AppConst.PG_STATE_LOAD_FINISH;
//        switch (pageNum) {
//            case 1:
//                if (res == null) {
//                    state = AppConst.PG_STATE_LOAD_FINISH_FAIL;
//                    break;
//                }
//                if (res.getItems().isEmpty()) {
//                    state = AppConst.PG_STATE_LOAD_FINISH_NO_DATA;
//                    break;
//                }
//                state = AppConst.PG_STATE_LOAD_FINISH;
//                break;
//            default:
//                if (res == null) {
//                    state = AppConst.PG_STATE_LOAD_MORE_FINISH_FAIL;
//                    break;
//                }
//                if (res.getItems().isEmpty()) {
//                    state = AppConst.PG_STATE_LOAD_MORE_FINISH_NO_DATA;
//                    break;
//                }
//                state = AppConst.PG_STATE_LOAD_MORE_FINISH;
//                break;
//
//        }
//        return state;
//    }
//
//    public void queryUserMsg(final String msgColumn, final int pageNum, int pageSize) {
//        msgModel.queryUserMsg(accessToken, teacherId, accountId, msgColumn, pageNum, pageSize, new RequestListener<MessageRet>() {
//            @Override
//            public void onSuccess(MessageRet res) {
//                Message msg = Message.obtain();
//                msg.what = getRetState(pageNum, res);
//                if (msgColumn.equals(AppConst.MSG_TYPE_MYMSG)) {
//                    msg.arg1 = MessageFragment.MY_MSG;
//                } else {
//                    msg.arg1 = MessageFragment.ZX_RECOMMAND;
//                }
//                msg.obj = res;
//                mHandler.sendMessage(msg);
//            }
//
//            @Override
//            public void onFail(HttpResponse response, Exception ex) {
//                Message msg = Message.obtain();
//                if (pageNum == 1) {
//                    msg.what = AppConst.PG_STATE_LOAD_FINISH_FAIL;
//                } else {
//                    msg.what = AppConst.PG_STATE_LOAD_MORE_FINISH_FAIL;
//                }
//                if (msgColumn.equals(AppConst.MSG_TYPE_MYMSG)) {
//                    msg.arg1 = MessageFragment.MY_MSG;
//                } else {
//                    msg.arg1 = MessageFragment.ZX_RECOMMAND;
//                }
//                msg.obj = response.getMessage();
//                mHandler.sendMessage(msg);
//            }
//
//        });
//    }
//
//    public void cleanUserMsg(ArrayList<MessageInfo> deleteableMsgs, final int msgColumn) {
//        String[] rowkeys = new String[deleteableMsgs.size()];
//
//        for (int i = 0; i < deleteableMsgs.size(); i++) {
//            rowkeys[i] = deleteableMsgs.get(i).getRowKey();
//        }
//
//        msgCenterView.startRequestProgress("清除消息...");
//        msgModel.cleanUserMsgInfo(accessToken, teacherId, rowkeys, new RequestListener<ResultInfo>() {
//            @Override
//            public void onSuccess(ResultInfo res) {
//                Message msg = Message.obtain();
//                msg.what = AppConst.MSG_CLEAN_SUCCESS;
//                msg.arg1 = msgColumn;
//                mHandler.sendMessage(msg);
//                msgCenterView.endRequestProgress();
//            }
//
//            @Override
//            public void onFail(HttpResponse response, Exception ex) {
//                Message msg = Message.obtain();
//                msg.what = AppConst.MSG_CLEAN_FAIL;
//                msg.obj = response.getMessage();
//                mHandler.sendMessage(msg);
//                msgCenterView.endRequestProgress();
//            }
//
//        });
//    }
//
//    public void cleanUserMsgAll(final int msgColumn) {
//        msgCenterView.startRequestProgress("清除消息...");
//        String msgcolumns;
//        if (msgColumn == MessageFragment.MY_MSG) {
//            msgcolumns = AppConst.MSG_TYPE_MYMSG;
//        } else {
//            msgcolumns = AppConst.MSG_TYPE_REC;
//        }
//        msgModel.cleanUserMsgAll(accessToken, teacherId, msgcolumns, new RequestListener<ResultInfo>() {
//            @Override
//            public void onSuccess(ResultInfo res) {
//                Message msg = Message.obtain();
//                msg.what = AppConst.MSG_CLEAN_SUCCESS;
//                msg.arg1 = msgColumn;
//                mHandler.sendMessage(msg);
//                msgCenterView.endRequestProgress();
//            }
//
//            @Override
//            public void onFail(HttpResponse response, Exception ex) {
//                Message msg = Message.obtain();
//                msg.what = AppConst.MSG_CLEAN_FAIL;
//                msg.obj = response.getMessage();
//                mHandler.sendMessage(msg);
//                msgCenterView.endRequestProgress();
//            }
//
//        });
//    }
//
//}
